<template>
  <div class="container">
    <div class="top">
      <el-input
        style="width:200px;margin-bottom:5px"
        v-model="search.searchCode"
        placeholder="请输入商超区域"
        clearable
      ></el-input>
      <el-button
        size="small"
        type="primary"
        class="handleSearch"
        icon="el-icon-search"
        @click="handleSearch()"
      >查询</el-button>
      <!-- <el-button
        class="add"
        size="small"
        type="primary"
        @click="addPermission"
        icon="el-icon-circle-plus"
      >添加商超区域</el-button> -->
    </div>
    <el-table max-height="600" :data="tableData" border style="width: 100%" empty-text="暂无数据">
      <el-table-column prop="name" label="区域名称" align="center"></el-table-column>
      <el-table-column prop="code" label="区域Code" align="center"></el-table-column>
      <!-- <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope)">编辑</el-button>
          <el-button size="mini" icon="el-icon-delete" type="danger" @click="handleDelete(scope)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <pagination @page="handleSizeChange" @pagesize="handleCurrentChange" :pageData="pageData"></pagination>
    <!-- 添加商超采购员dialog -->
    <buyerRegionDialog :dialog="dialog" :regions="regions" @upData="getData"></buyerRegionDialog>
  </div>
</template>
<script>
import Pagination from "@/components/pagination";
import { getRegionList } from "@/api/buyerRegion/region";
import { getdelRegion } from "@/api/buyerRegion/region";
import BuyerRegionDialog from "@/components/buyerRegionDialog";
export default {
  components: {
    pagination: Pagination,
    buyerRegionDialog: BuyerRegionDialog
  },
  data() {
    return {
      dialog: {
        centerDialogVisible: false,
        dialogType: ""
      },
      regions: {
        name: "",
        id: ""
      },
      //页面数据
      tableData: [],
      //分页
      pageData: {
        pageSizes: [10, 20],
        pageSize: 10,
        page: 1,
        total: null,
        layout: "total, sizes, prev, pager, next, jumper"
      },
      search: {
        searchCode: ""
      }
    };
  },

  created() {
    //页面数据
    this.getData();
  },
  methods: {
    //页面数据
    getData() {
      let data = {
        limit: this.pageData.pageSize,
        page: this.pageData.page,
        name: this.search.searchCode
      };
      getRegionList(data)
        .then(res => {
          if (res.code == 0) {
            this.tableData = res.data.paginate.data;
            this.pageData.page = res.data.paginate.current_page;
            this.pageData.pagesize = res.data.paginate.per_page;
            this.pageData.total = res.data.paginate.total;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //添加人员
    addPermission() {
      this.dialog.centerDialogVisible = true;
      this.dialog.dialogType = "";
      this.regions.name = "";
      this.regions.id = "";
    },
    //编辑
    handleEdit(scope) {
      this.dialog.centerDialogVisible = true;
      this.dialog.dialogType = "edit";
      this.regions.name = scope.row.name;
      this.regions.id = scope.row.id;
    },
    //删除
    handleDelete(scope) {
      this.$confirm("是否删除该条信息?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let data = {
            id: scope.row.id
          };
          getdelRegion(data).then(res => {
            if (res.code == 0) {
              this.getData();
              this.$message({
                type: "success",
                message: res.msg
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 本地搜索
    handleSearch() {
      this.pageData.page = 1;
      this.pageData.total = null;
      this.getData();
    },

    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;

      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;

      this.getData();
    },
    //选取
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>
<style scoped>
.top {
  position: relative;
}

.add {
  position: absolute;
  right: 0;
  top: 4px;
}
.pagination {
  text-align: right;
  padding: 10px;
}
</style>